package com.techstar.api.service;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.techstar.api.service.city.DistrictCongestJunctionService;
import com.techstar.api.service.city.DistrictCongestRankService;
import com.techstar.api.service.city.DistrictCongestSectionService;
import com.techstar.api.service.city.DistrictCongestTrendService;
import com.techstar.api.service.city.DistrictFlowRankService;
import com.techstar.api.service.city.DistrictFlowTrendService;
import com.techstar.api.service.city.DistrictOnlineVehicleService;
import com.techstar.api.service.city.DistrictRoadSpeedService;
import com.techstar.api.service.city.DistrictSectionFlowService;
import com.techstar.api.service.city.SectionFlowTrendService;
import com.techstar.api.service.expressway.FreewayCongestRankService;
import com.techstar.api.service.expressway.FreewayCongestSectionService;
import com.techstar.api.service.expressway.FreewayCongestStationService;
import com.techstar.api.service.expressway.FreewayCongestTrendService;
import com.techstar.api.service.expressway.FreewayFlowTrendService;
import com.techstar.api.service.expressway.StationFlowRankService;
import com.techstar.api.service.expressway.StationFlowTrendService;
import com.techstar.api.service.gis.TrafficAccidentService;
import com.techstar.api.service.gis.TrafficEventService;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author EinIce
 * @description API接口启动配置
 * @date 2021年6月24日
 *
 */
@Slf4j
@Service
public class TrafficFactory {
	private List<String> distId = Arrays.asList("4553","5318","5319","5320","5321","5322","5323","5324","5325","5326");
	private List<String> highwayId = Arrays.asList("9999","34583","34584","34753","34754","34761",
			"34762","34773","34774","34791","34792","34803","34804","34823","34824","35013","35014",
			"35023","35024","35173","35174","35181","35182","35191","35192");
	private List<String> flowSiteCode = Arrays.asList("100001","100002","100003","100004");
	
	@Autowired
	private DistrictCongestJunctionService districtCongestJunctionService;
	@Autowired
	private DistrictCongestRankService districtCongestRankService;
	@Autowired
	private DistrictCongestSectionService districtCongestSectionService;
	@Autowired
	private DistrictCongestTrendService districtCongestTrendService;
	
	@Scheduled(fixedDelay = 1 * 60 * 1000)
	public void cityFirstService() {
		log.info("CityFirstService start!");
		distId.forEach(l->districtCongestJunctionService.query(l));
		districtCongestRankService.query();
		districtCongestSectionService.query();
		districtCongestTrendService.query();
		log.info("CityFirstService finish!");
	}
	
	@Autowired
	private DistrictFlowRankService districtFlowRankService;
	@Autowired
	private DistrictFlowTrendService districtFlowTrendService;
	@Autowired
	private DistrictOnlineVehicleService districtOnlineVehicleService;
	@Autowired
	private DistrictSectionFlowService districtSectionFlowService;
	@Autowired
	private SectionFlowTrendService sectionFlowTrendService;
	@Autowired
	private DistrictRoadSpeedService districtRoadSpeedService;
	
	@Scheduled(fixedDelay = 1 * 60 * 1000)
	public void citySecondService() {
		log.info("CitySecondService start!");
//		distId.forEach(l->districtOnlineVehicleService.query(l));
//		传入固定行政编码
		districtOnlineVehicleService.query("4553");
		districtFlowRankService.query();
		distId.forEach(d->{
			districtFlowTrendService.query(d);
		});
		districtSectionFlowService.query();
		flowSiteCode.forEach(l->sectionFlowTrendService.query(l));
		districtRoadSpeedService.query("1");
		districtRoadSpeedService.query("2");
		districtRoadSpeedService.query("3");
		log.info("CitySecondService finish!");
	}
	
	@Autowired
	private FreewayCongestRankService freewayCongestRankService;
	@Autowired
	private FreewayCongestSectionService freewayCongestSectionService;
	@Autowired
	private FreewayCongestStationService freewayCongestStationService;
	@Autowired
	private FreewayCongestTrendService freewayCongestTrendService;
	@Scheduled(fixedDelay = 1 * 60 * 1000)
	public void cityFourthService() {
		log.info("CityFourthService start!");
		freewayCongestRankService.query();
		freewayCongestSectionService.query();
		freewayCongestStationService.query();
		highwayId.forEach(l->{freewayCongestTrendService.query(l);});
		log.info("CityFourthService finish!");
	}
	
	@Autowired
	private StationFlowRankService stationFlowRankService;
	@Autowired
	private StationFlowTrendService stationFlowTrendService;
	@Autowired
	private FreewayFlowTrendService freewayFlowTrendService;
	
	private List<String> station = Arrays.asList("200001","200002","200003","200004","200005","200006");
	
	@Scheduled(fixedDelay = 1 * 60 * 1000)
	public void cityFifthService() {
		log.info("CityFifthService start!");
		stationFlowRankService.query();
		station.forEach(l->stationFlowTrendService.query(l));
		highwayId.forEach(l->freewayFlowTrendService.query(l));
		log.info("CityFifthService finish!");
	}
	
	@Autowired
	private TrafficAccidentService TrafficAccidentService;
	@Autowired
	private TrafficEventService TrafficEventService;
	@Scheduled(fixedDelay = 1 * 60 * 1000)
	public void gisService() {
		log.info("gisService start!");
		TrafficEventService.query();
		TrafficAccidentService.query();
		log.info("gisService finish!");
	}
}
